home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11306 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  51 lines

  1. Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
  2. From: shappir@libra.math.tau.ac.il (Shappir Dan)
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: Enumerated type converted to pointer? Legal?
  5. Followup-To: comp.lang.c++,comp.lang.c++.moderated
  6. Date: 13 Mar 1996 17:19:58 -0000
  7. Organization: School of Math & CS - Tel Aviv University , Tel Aviv , ISRAEL.
  8. Sender: cppmods@netlab.cs.rpi.edu
  9. Approved: devitto@ferndown.ate.slb.com
  10. Message-ID: <4i703u$1gl@netlab.cs.rpi.edu>
  11. References: <4hobji$mco@netlab.cs.rpi.edu>
  12. NNTP-Posting-Host: netlab.cs.rpi.edu
  13. X-Original-Date: 13 Mar 1996 09:21:33 GMT
  14.  
  15. { comp.std.c++ removed from followups. -mod}
  16.  
  17. Brad Stowers (bstowers@pobox.com) wrote:
  18.  
  19. : Compile and run the above program.  Is it just me, or should the last line
  20. : of the main() function ( FooBar(x, mdType1); ) have caused a type mismatch
  21. : error?  I think I know why it didn't:  mdType1 evaluates to an integer with
  22. : a value of 0, which is a valid value to pass as a pointer.  In support of
  23. : this theory, the line:
  24.  
  25. This is due to one of the differences between C and C++. In C the NULL
  26. pointer is defined as ((void*)0) while in C++ it's simply 0. This can raise
  27. all sorts of type conversion problems, for example:
  28.  
  29. void foo(int bar) { ... }
  30. void foo(void* bar) { ... }
  31.  
  32. ...
  33. foo(0);
  34. ...
  35.  
  36. The compiler will not be able to determine which version of foo to call.
  37.  
  38. Another type issue raised here is the implicit conversion between enums and
  39. integers. Like all implicit conversion this is useful but can also be
  40. annoying. Can anyone present a method for defining an enum or and enum-like
  41. type that cannot be implicitly converted to int ?
  42.  
  43. Dan Shappir
  44. shappir@math.tau.ac.il
  45.  
  46.  
  47.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  48.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  49.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  50.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  51.